using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Rensoft.CRM.Client.AccountsAPI;
using Rensoft.CRM.Client.Editors;
using Rensoft.CRM.Client.Properties;

namespace Rensoft.CRM.Client.ItemViews
{
    public partial class MailboxView : Rensoft.CRM.Client.ItemViews.ServiceView
    {
        public override Image NewButtonImage
        {
            get
            {
                return Resources.Mailbox;
            }
        }

        public MailboxView(Program program)
            : base(program)
        {
            InitializeComponent();
        }

        protected override void PerformLoad()
        {
            AccountsService service = new AccountsService();
            service.UseDefaultCredentials = true;
            base.ServiceArray = service.MailboxFetchAll();
        }

        protected override void OnRetrieveVirtualItem(object sender, RetrieveVirtualItemEventArgs e)
        {
            MailboxService mailbox = (MailboxService)base.ServiceArray[e.ItemIndex];

            e.Item = new ListViewItem(
                new string[] {
                    mailbox.Title,
                    mailbox.CreateDate.ToShortDateString(),
                    mailbox.UpdateDate.ToShortDateString() });

            e.Item.Tag = mailbox;

            base.OnRetrieveVirtualItem(sender, e);
        }

        protected override void PerformEditorOpen(object tag)
        {
            MailboxService mailbox = (MailboxService)tag;
            Program.LoadEditorAsync(new MailboxEditor(Program, mailbox));

            base.PerformEditorOpen(tag);
        }

        internal override BaseEditor GetEditor()
        {
            return new MailboxEditor(Program);
        }
    }
}

